﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CodeAuto.Pages
{
    public partial class ProjectDelete : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int productid = Convert.ToInt32(Request["productid"]);
            Models.T_Project project = new Models.T_Project();
            project.Id = productid;
            DavidDB.ADO.DBManager db = new DavidDB.ADO.DBManager();
            db.Delete(project);

            Models.T_Table table = new Models.T_Table();
            table.ProjectId = productid;
            var query = db.GetSomeObject(table);

            foreach (Models.T_Table t in query)
            {
                Models.T_Field tf = new Models.T_Field();
                tf.TableId = t.Id;
                var fields = db.GetSomeObject(tf);
                foreach (Models.T_Field _tf in fields)
                {
                    db.Delete(_tf);
                }
                db.Delete(t);
            }

            db.Commit();
            db.Dispose();
            Response.Redirect("../Default.aspx");
        }
    }
}